#include "binaryTree.h"
#include "queue.h"

void
LevelOrder(BTNode* root)
{
  Queue q;
  QueueInit(&q);
  if (root)
    QueuePush(&q, root);

  while (!QueueEmpty(&q)) {
    BTNode* front = QueueFront(&q);
    printf("%d ", front->val);
    QueuePop(&q);

    if (front->left) {
      QueuePush(&q, front->left);
    }
    if (front->right) {
      QueuePush(&q, front->right);
    }
  }
  printf("\n");
  QueueDestroy(&q);
}